package com.pipline2;

import java.util.Arrays;
import java.util.List;

/**
 * @author ycd0075
 * @date 2023-07-11 11:25
 */
public class TestPipline {


    private TestPipline() {

    }

    public static <T> Pipeline<T> getInstance(List<? extends AbstractPipeline<? extends T>> pipelines) {
        if (pipelines == null || pipelines.isEmpty()) {
            throw new IllegalArgumentException("empty pipelines!");
        }
        @SuppressWarnings("unchecked")
        AbstractPipeline<T>[] a = (AbstractPipeline<T>[]) pipelines.toArray(new AbstractPipeline[0]);
        AbstractPipeline<T> p = a[0];
        for (int i = 1; i < a.length; ++i) {
            p.setNext(a[i]);
            p = a[i];
        }
        p.setNext(null);
        return a[0];
    }

    public static void main(String[] args) {
        DemoPipeline pipeline1 = new DemoPipeline("demo1");
        Demo2Pipeline pipeline2 = new Demo2Pipeline("demo2");
        TestPipline.getInstance(Arrays.asList(pipeline1, pipeline2)).process(null, null);
    }
}
